import { Service } from "typedi";
import { ElLoading } from "@chulei-ui/element-plus";
import { UniverseCategory, UniverseGroup } from "./universe/entity";

import { database, esi } from "./index";
import type { ObjectLiteral, Repository } from "typeorm";

@Service()
export class UniverseService {
  private readonly categoryRepository: Repository<UniverseCategory>;
  private readonly groupRepository: Repository<UniverseGroup>;
  constructor() {
    this.categoryRepository = database.getRepository(UniverseCategory);
    this.groupRepository = database.getRepository(UniverseGroup);
  }

  getCategories() {
    return this.categoryRepository
      .createQueryBuilder("category")
      .leftJoinAndSelect("category.groups", "group")
      .leftJoinAndSelect("group.category", "category2")
      .where("category.published = :published", { published: true }) // 对 category 的过滤
      .andWhere("group.published = :published", { published: true }) // 对 groups 的过滤
      .getMany();
  }
}
